<?php

function __system__providers(){
    return [
        /*
         * Laravel Framework Service Providers...
         */
        Illuminate\Auth\AuthServiceProvider::class,
        Illuminate\Broadcasting\BroadcastServiceProvider::class,
        Illuminate\Bus\BusServiceProvider::class,
        Illuminate\Cache\CacheServiceProvider::class,
        Illuminate\Foundation\Providers\ConsoleSupportServiceProvider::class,
        Illuminate\Cookie\CookieServiceProvider::class,
        Illuminate\Database\DatabaseServiceProvider::class,
        Illuminate\Encryption\EncryptionServiceProvider::class,
        Illuminate\Filesystem\FilesystemServiceProvider::class,
        Illuminate\Foundation\Providers\FoundationServiceProvider::class,
        Illuminate\Hashing\HashServiceProvider::class,
        Illuminate\Mail\MailServiceProvider::class,
        Illuminate\Notifications\NotificationServiceProvider::class,
        Illuminate\Pagination\PaginationServiceProvider::class,
        Illuminate\Pipeline\PipelineServiceProvider::class,
        Illuminate\Queue\QueueServiceProvider::class,
        Illuminate\Redis\RedisServiceProvider::class,
        Illuminate\Auth\Passwords\PasswordResetServiceProvider::class,
        Illuminate\Session\SessionServiceProvider::class,
        Illuminate\Translation\TranslationServiceProvider::class,
        Illuminate\Validation\ValidationServiceProvider::class,
        Illuminate\View\ViewServiceProvider::class,
        Maatwebsite\Excel\ExcelServiceProvider::class,

        /*
         * Package Service Providers...
         */
        Laravel\Scout\ScoutServiceProvider::class,
        SimpleSoftwareIO\QrCode\QrCodeServiceProvider::class,
        Intervention\Image\ImageServiceProvider::class,
//            App\Providers\DuskServiceProvider::class,
        /*
         * Application Service Providers...
         */
        App\Providers\MysqlUpdateProvider::class,
        App\Providers\AppServiceProvider::class,
        App\Providers\AuthServiceProvider::class,
        App\Providers\BroadcastServiceProvider::class,
        App\Providers\EventServiceProvider::class,
        App\Providers\RouteServiceProvider::class,
        Matchish\ScoutElasticSearch\ElasticSearchServiceProvider::class,
        \Dcat\Admin\AdminServiceProvider::class,
        App\Providers\QueryCounterServiceProvider::class
    ];
}

function __system__aliases(){
    return [
        'App' => Illuminate\Support\Facades\App::class,
        'Arr' => Illuminate\Support\Arr::class,
        'Artisan' => Illuminate\Support\Facades\Artisan::class,
        'Auth' => Illuminate\Support\Facades\Auth::class,
        'Blade' => Illuminate\Support\Facades\Blade::class,
        'Broadcast' => Illuminate\Support\Facades\Broadcast::class,
        'Bus' => Illuminate\Support\Facades\Bus::class,
        'Cache' => Illuminate\Support\Facades\Cache::class,
        'Config' => Illuminate\Support\Facades\Config::class,
        'Cookie' => Illuminate\Support\Facades\Cookie::class,
        'Crypt' => Illuminate\Support\Facades\Crypt::class,
        'DB' => Illuminate\Support\Facades\DB::class,
        'Eloquent' => Illuminate\Database\Eloquent\Model::class,
        'Event' => Illuminate\Support\Facades\Event::class,
        'File' => Illuminate\Support\Facades\File::class,
        'Gate' => Illuminate\Support\Facades\Gate::class,
        'Hash' => Illuminate\Support\Facades\Hash::class,
        'Http' => Illuminate\Support\Facades\Http::class,
        'Lang' => Illuminate\Support\Facades\Lang::class,
        'Log' => Illuminate\Support\Facades\Log::class,
        'Mail' => Illuminate\Support\Facades\Mail::class,
        'Notification' => Illuminate\Support\Facades\Notification::class,
        'Password' => Illuminate\Support\Facades\Password::class,
        'Queue' => Illuminate\Support\Facades\Queue::class,
        'Redirect' => Illuminate\Support\Facades\Redirect::class,
        'Redis' => Illuminate\Support\Facades\Redis::class,
        'Request' => Illuminate\Support\Facades\Request::class,
        'Response' => Illuminate\Support\Facades\Response::class,
        'Route' => Illuminate\Support\Facades\Route::class,
        'Schema' => Illuminate\Support\Facades\Schema::class,
        'Session' => Illuminate\Support\Facades\Session::class,
        'Storage' => Illuminate\Support\Facades\Storage::class,
        'Str' => Illuminate\Support\Str::class,
        'URL' => Illuminate\Support\Facades\URL::class,
        'Validator' => Illuminate\Support\Facades\Validator::class,
        'View' => Illuminate\Support\Facades\View::class,
        'QrCode' => SimpleSoftwareIO\QrCode\Facades\QrCode::class,
        'Image' => Intervention\Image\Facades\Image::class,
        'Excel' => Maatwebsite\Excel\Facades\Excel::class,
    ];
}

function __system__http__code(){
    return [
        200 => '成功',
        200000 => '权限不足',
        200001 => '缺少必要的参数',
        200002 => '数据库错误',
        200003 => '无记录',
        200004 => '参数检验不合法',
        200005 => '缓存系统不可用',
        200006 => '系统错误',
        200007 => '已检测',
        200008 => '配置错误',
        200009 => '已过期',
        200010 => '重复动作',
        200011 => '金币不足',
        200012 => '余额不足！请前往我的钱包充值',
        200013 => '提现失败',
        200014 => '暂未完成',
        200015 => '未登录状态',
        200016 => '违规内容',
        200017 => '上传失败',
        200018 => '文本过长',
        200019 => '附件缺失必要参数',
        200020 => '超过最大可上传附件数',
        200021 => '投票贴不可以上传附件或音频',
        200022 => '不支持的附件类型',
        200023 => '超过最大可上传音频数',
        200024 => '音频缺失必要参数',
        200025 => '一个字也没有',
        200026 => '请勿随意发布测试内容',
        200027 => '您动作过快，小的追不上您，请您稍后再试',
        200028 => '您发布的笔记已达到当天最大数量',
        200029 => '付费内容配置错误',
        200030 => '付费数额超过限制',
        200031 => '字数过少',
        200032 => '篇幅付费仅支持50-90%',
        200033 => '待定',
        200034 => '待定',
        200035 => '您已经购买过了',
        200036 => '购买成功',
        200037 => '购买失败',
        200038 => '不能购买自己的内容',
        200039 => '该名字已经有人使用了，你换一个吧',
        200040 => '不能和自己聊天',
        200041 => '默认昵称不能发布内容',
        200042 => '未达到条件',
        200043 => 'custom',
        200044 => '操作超时',
        200045 => '待人机验证',
        200046 => '超过限定值',
        200047 => '需二次查询',

        // 代码协议
        700000 => 'you are not unlocked this',
        700001 => '您的账号已申请注销',
        700002 => '您的账号已进入系统黑名单',
        700003 => '',

        //工具
        300001 => '小程序码生成失败',

        //用户
        500001 => '微信登录失败',
        503001 => '授权失败',
        503002 => '缺少token',
        503003 => 'token过期',
        503004 => '文章保存失败',
        503005 => '移动应用openid未知，建议您在app端登录一次',
        503006 => '小程序端openid未知，建议您在小程序登录一次',
        503007 => '公众号端openid未知，建议您在在公众号登录一次',
        503008 => '网站端openid未知，建议您在在网站登录一次',
        503009 => '小商店端openid未知，建议您在在小商店登录一次',

        403017 => '临近定时时间不能取消发送任务',
        403018 => '临近定时时间不能修改发送任务',
        403019 => '超过发送时间不能发送',
        403020 => '缺少发表记录ID参数',
        403021 => '关注成功',
        403022 => '取消关注',
        403023 => '不能关注自己',
        //笔记
        416001 => '发帖失败',
        416002 => '签名添加失败',
        416003 => '评论点赞',
        416004 => '评论取消点赞',
        416005 => '笔记已下架',
        416006 => '笔记待审核',
        416007 => '笔记被驳回',
        // 板块
        421001 => '不能重复添加板块',
        //SHOP
        800001 => '该规格暂时没有库存啦！',
        800002 => '库存不足',
        800003 => '收货地址不能为空',
        800004 => '您已经达到该商品限购次数',
        800010 => '该订单已经催发货了，我们会尽快为您处理。',

        // 微信小程序数据预拉取
        2009001 => '首页预拉取数据',



        //固定码api
        1001001 => '参数未携带author',
        1001002 => '唯一性id参数为空',
        1001003 => '评论的文章不存在',
        1001004 => '评论文章的作者不存在',
        1001005 => '该评论对应的父级评论不存在',
        1001006 => '动作列表为空',
        1001007 => 'domain参数为空或非法',
    ];
}

function __system__is__extensions__in($id){
    return in_array($id, ['dcat-admin.form-step', 'sparkinzy.dcat-viewer', 'lty5240.dcat-easy-sku', 'jyil.crontab']);
}

function __system__del__dir($path){
    if(is_dir($path)){
        $p=scandir($path);
        foreach($p as $val){
            if($val !="." && $val !=".."){
                if(is_dir($path.$val)){
                    __system__del__dir($path.$val.'/');
                    @rmdir($path.$val.'/');
                }else{
                    @unlink(rtrim($path, '/\\') . '/' .$val);
                }
            }
        }
    }
}

function __system__paycode__tip__($paycode){
    $status = false;
    $result = [
        'text' => '',
        'tip' => ''
    ];
    global $__MINI_GLOBAL_TENANT_ID__;
    if($__MINI_GLOBAL_TENANT_ID__ > 0){
        return $result;
    }
    $img_src = \App\Wen\Utils\Settings::get('mini_pay_code_'.$paycode, '');
    if($paycode == 1){
        global $__MINI_GLOBAL_PAYCODE_1__;
        if($__MINI_GLOBAL_PAYCODE_1__){
            $status = true;
        }
    }else if($paycode == 2){
        global $__MINI_GLOBAL_PAYCODE_2__;
        if($__MINI_GLOBAL_PAYCODE_2__){
            $status = true;
        }
    }else if($paycode == 3){
        global $__MINI_GLOBAL_PAYCODE_3__;
        if($__MINI_GLOBAL_PAYCODE_3__){
            $status = true;
        }
    }else if($paycode == 4){
        global $__MINI_GLOBAL_PAYCODE_4__;
        if($__MINI_GLOBAL_PAYCODE_4__){
            $status = true;
        }
    }else if($paycode == 5){
        global $__MINI_GLOBAL_PAYCODE_5__;
        if($__MINI_GLOBAL_PAYCODE_5__){
            $status = true;
        }
    }else if($paycode == 6){
        global $__MINI_GLOBAL_PAYCODE_6__;
        if($__MINI_GLOBAL_PAYCODE_6__){
            $status = true;
        }
    }else if($paycode == 7){
        global $__MINI_GLOBAL_PAYCODE_7__;
        if($__MINI_GLOBAL_PAYCODE_7__){
            $status = true;
        }
    }else if($paycode == 8){
        global $__MINI_GLOBAL_PAYCODE_8__;
        if($__MINI_GLOBAL_PAYCODE_8__){
            $status = true;
        }
    }else if($paycode == 9){
        global $__MINI_GLOBAL_PAYCODE_9__;
        if($__MINI_GLOBAL_PAYCODE_9__){
            $status = true;
        }
    }else if($paycode == 10){
        global $__MINI_GLOBAL_PAYCODE_10__;
        if($__MINI_GLOBAL_PAYCODE_10__){
            $status = true;
        }
    }else if($paycode == 11){
        global $__MINI_GLOBAL_PAYCODE_11__;
        if($__MINI_GLOBAL_PAYCODE_11__){
            $status = true;
        }
    }else if($paycode == 12){
        global $__MINI_GLOBAL_PAYCODE_12__;
        if($__MINI_GLOBAL_PAYCODE_12__){
            $status = true;
        }
    }else if($paycode == 13){
        global $__MINI_GLOBAL_PAYCODE_13__;
        if($__MINI_GLOBAL_PAYCODE_13__){
            $status = true;
        }
    }else if($paycode == 14){
        global $__MINI_GLOBAL_PAYCODE_14__;
        if($__MINI_GLOBAL_PAYCODE_14__){
            $status = true;
        }

    }else if($paycode == 15){
        global $__MINI_GLOBAL_PAYCODE_15__;
        if($__MINI_GLOBAL_PAYCODE_15__){
            $status = true;
        }
    }else if($paycode == 16){
        global $__MINI_GLOBAL_PAYCODE_16__;
        if($__MINI_GLOBAL_PAYCODE_16__){
            $status = true;
        }
    }else if($paycode == 17){
        global $__MINI_GLOBAL_PAYCODE_17__;
        if($__MINI_GLOBAL_PAYCODE_17__){
            $status = true;
        }

    }else if($paycode == 18){
        global $__MINI_GLOBAL_PAYCODE_18__;
        if($__MINI_GLOBAL_PAYCODE_18__){
            $status = true;
        }
    }else if($paycode == 19){
        global $__MINI_GLOBAL_PAYCODE_19__;
        if($__MINI_GLOBAL_PAYCODE_19__){
            $status = true;
        }
    }else if($paycode == 20){
        global $__MINI_GLOBAL_PAYCODE_20__;
        if($__MINI_GLOBAL_PAYCODE_20__){
            $status = true;
        }
    }else if($paycode == 23){
        global $__MINI_GLOBAL_PAYCODE_23__;
        if($__MINI_GLOBAL_PAYCODE_23__){
            $status = true;
        }
    }else if($paycode == 24){
        global $__MINI_GLOBAL_PAYCODE_24__;
        if($__MINI_GLOBAL_PAYCODE_24__){
            $status = true;
        }
    }else if($paycode == 26){
        global $__MINI_GLOBAL_PAYCODE_26__;
        if($__MINI_GLOBAL_PAYCODE_26__){
            $status = true;
        }
    }else if($paycode == 29){
        global $__MINI_GLOBAL_PAYCODE_29__;
        if($__MINI_GLOBAL_PAYCODE_29__){
            $status = true;
        }
    }else if($paycode == 30){
        global $__MINI_GLOBAL_PAYCODE_30__;
        if($__MINI_GLOBAL_PAYCODE_30__){
            $status = true;
        }
    }else if($paycode == 34){
        global $__MINI_GLOBAL_PAYCODE_34__;
        if($__MINI_GLOBAL_PAYCODE_34__){
            $status = true;
        }
    }

    if($status){
        $result['text'] = '<a class="mini_global_admin_open_not_support_tip success">已解锁</a>';
        $result['tip'] = '恭喜';
    }else{
        $result['text'] = '<div target="_blank" class="mini_global_admin_open_not_support_tip">付费'.$paycode.'未解锁</div>';
        $result['tip'] = '<span class="img-wrap"><img class="not_support_tip_code" src="'.$img_src.'"></span>';
    }

    return $result;

}


function __system__admin__config__($tenant_id = 0){
    global $__MINI_GLOBAL_TENANTS_ARR__;
    $multi_app_arr = [];
    foreach ($__MINI_GLOBAL_TENANTS_ARR__ as $key){
        if($key > 0){
            $multi_app_arr['admin_'.$key] = true;
        }
    }
    return [
        'name' => 'MiniSNS',
        'logo' =>  '<img src="'.($tenant_id == 0 ? env('MAIN_SITE_ADMIN_LOGO', '/statics/minisns.svg') : env('TENANT_ADMIN_LOGO', '/statics/minisns.svg')).'" width="80%" style="max-width: unset;max-height: unset;">',
        'favicon' => $tenant_id == 0 ? env('MAIN_SITE_ADMIN_AVATAR', '/statics/mlogo.svg') : env('TENANT_ADMIN_AVATAR', '/statics/mlogo.svg'),
        'logo_url'=> $tenant_id == 0 ? env('MAIN_SITE_ADMIN_AVATAR', '/statics/mlogo.svg') : env('TENANT_ADMIN_AVATAR', '/statics/mlogo.svg'),
        'logo-mini' => '<img src="'.($tenant_id == 0 ? env('MAIN_SITE_ADMIN_AVATAR', '/statics/mlogo.svg') : env('TENANT_ADMIN_AVATAR', '/statics/mlogo.svg')).'" style="width: 45px;">',
        'default_avatar' => $tenant_id == 0 ? env('MAIN_SITE_ADMIN_AVATAR', '/statics/mlogo.svg') : env('TENANT_ADMIN_AVATAR', '/statics/mlogo.svg'),
        'route' => [
            'domain' => env('ADMIN_ROUTE_DOMAIN'),
            'prefix' => env('APP_ADMIN_PREFIX', 'admin'). ( $tenant_id > 0 ? '_'.$tenant_id : ''),
            'namespace' => 'App\\Admin\\Controllers',
            'middleware' => ['web', 'admin'],
            'enable_session_middleware' => false,
        ],
        'directory' => $tenant_id == 0 ? app_path('Admin') : app_path('Admin_1'),
        'title' =>  $tenant_id == 0 ? env('MAIN_SITE_ADMIN_NAME', 'MiniSNS Admin') : env('TENANT_ADMIN_NAME', 'MiniSNS Admin'),
        'assets_server' => env('ADMIN_ASSETS_SERVER'),
        'https' => true,
        'auth' => [
            'enable' => true,
            'controller' => App\Admin\Controllers\AuthController::class,
            'guard' => 'admin_'.$tenant_id,
            'guards' => [
                'admin_'.$tenant_id => [
                    'driver'   => 'session',
                    'provider' => 'admin_'.$tenant_id,
                ],
            ],

            'providers' => [
                'admin_'.$tenant_id => [
                    'driver' => 'eloquent',
                    'model'  => $tenant_id == 0 ? 'Dcat\Admin\Models\Administrator' : 'Dcat\Admin\Models\Administrator_'.$tenant_id,
                ],
            ],

            // Add "remember me" to login form
            'remember' => true,
            'except' => [
                'auth/login',
                'auth/logout',
            ],
            'enable_session_middleware' => false,
        ],

        'grid' => [
            'grid_action_class' => Dcat\Admin\Grid\Displayers\DropdownActions::class,
        ],
        'helpers' => [
            'enable' => true,
        ],
        'permission' => [
            'enable' => true,
            'except' => [
                'auth/login',
                'auth/logout',
                'auth/setting',
            ],

        ],

        'menu' => [
            'cache' => [
                'enable' => false,
                'store'  => 'file',
            ],
            'bind_permission' => true,
        ],
        'upload' => [
            'disk' => 'local',
            'directory' => [
                'image' => 'images',
                'file'  => 'files',
            ],
        ],
        'database' => [

            // Database connection for following tables.
            'connection' => '',

            // User tables and model.
            'users_table' => $tenant_id == 0 ? 'admin_users' : 'admin_users_'.$tenant_id,
            'users_model' => $tenant_id == 0 ? 'Dcat\Admin\Models\Administrator' : 'Dcat\Admin\Models\Administrator_'.$tenant_id,

            // Role table and model.
            'roles_table' => $tenant_id == 0 ? 'admin_roles' : 'admin_roles_'.$tenant_id,
            'roles_model' => $tenant_id == 0 ? 'Dcat\Admin\Models\Role' : 'Dcat\Admin\Models\Role_'.$tenant_id,

            // Permission table and model.
            'permissions_table' => $tenant_id == 0 ? 'admin_permissions' : 'admin_permissions_'.$tenant_id,
            'permissions_model' => $tenant_id == 0 ? 'Dcat\Admin\Models\Permission' : 'Dcat\Admin\Models\Permission_'.$tenant_id,

            // Menu table and model.
            'menu_table' => $tenant_id == 0 ? 'admin_menu' : 'admin_sub_menu',
            'menu_model' => $tenant_id == 0 ? Dcat\Admin\Models\Menu::class : Dcat\Admin\Models\AdminSubMenu::class,

            // Pivot table for table above.
            'role_users_table'       => $tenant_id == 0 ?  'admin_role_users' : 'admin_role_users_'.$tenant_id,
            'role_permissions_table' => $tenant_id == 0 ?  'admin_role_permissions' : 'admin_role_permissions_'.$tenant_id,
            'role_menu_table'        => $tenant_id == 0 ?  'admin_role_menu' : 'admin_role_menu_'.$tenant_id,
            'permission_menu_table'  => $tenant_id == 0 ?  'admin_permission_menu' : 'admin_permission_menu_'.$tenant_id,
            'settings_table'         => $tenant_id == 0 ?  'admin_settings' : 'admin_settings_'.$tenant_id,
            'extensions_table'       => $tenant_id == 0 ?  'admin_extensions' : 'admin_extensions_'.$tenant_id,
            'extension_histories_table' => $tenant_id == 0 ?  'admin_extension_histories' : 'admin_extension_histories_'.$tenant_id,
        ],
        'layout' => [
            // default, blue, blue-light, green
            'color' => 'green',
            'body_class' => 'mini-back',
            'sidebar_collapsed' => false,
            // light, primary, dark
            'sidebar_style' => 'light',
            'dark_mode_switch' => true,
            // bg-primary, bg-info, bg-warning, bg-success, bg-danger, bg-dark
            'navbar_color' => '',
        ],
        'exception_handler' => Dcat\Admin\Exception\Handler::class,
        'enable_default_breadcrumb' => true,
        'extension' => [
            'dir' => $tenant_id == 0 ? base_path('app/Extensions') : base_path('app/Extensions/tenant/'.$tenant_id),
        ],
        'multi_app' => $multi_app_arr,
    ];
}

function __timeMillion() {
    list($msec, $sec) = explode(' ', microtime());
    return (float)sprintf('%.0f', (floatval($msec) + floatval($sec)) * 1000);
}

